// pages/meetingDetail/meetingDetail.js
const app = getApp()
const ydb = wx.cloud.database()
Page({
  data: {
    myAppointment: null,
    appointmentRoom:null
  },
  async onLoad(options) {
    var that = this
    console.log(options)
    let myAppointmentRes = await ydb.collection("appointment").doc(options.id).get()
    let appointmentRoomRes = await ydb.collection("meetingRoom").doc(myAppointmentRes.data.meetingInfoId).get()
    console.log(myAppointmentRes.data);
    console.log(appointmentRoomRes.data)
    that.setData({
      myAppointment: myAppointmentRes.data,
      appointmentRoom:appointmentRoomRes.data,
    })
  },
  //取消预约
  async cancelIt() {
    var that = this 
    let showModalRes = await wx.showModal({
      title: '信息提示',
      content: '确认取消此预约吗',
      confirmText: "确认",
      showCancel: true,
    })
    if (showModalRes.confirm) {
      console.log("点击了确认");
      //更改预约表状态
      let updateRes1 = await ydb.collection("appointment").doc(that.data.myAppointment._id).update({
        data:{
          isDone : 0
        }
      })
      //更改会议室标志位状态
      let updateRes2 = await ydb.collection("meetingRoom").doc(that.data.myAppointment.meetingInfoId).update({
        data:{
          [`timeList.${that.data.myAppointment.timeListIndex}.openTime.${that.data.myAppointment.checkDay}.state`]: 1,
        }
      })
      console.log("执行成功")
      //刷新页面队列
      let showModalRes2 = await wx.showModal({
        title: '信息提示',
        content: '撤销预约成功～',
        confirmText: "确认",
        showCancel: false,
      })
      if (showModalRes2.confirm) {
        console.log("点击了确认");
        wx.navigateBack ()
      }
    }

  }
})